apiready = function () {
  api.parseTapmode();
  FastClick.attach(document.body);
  var header = $api.byId('aui-header');
  $api.fixStatusBar(header);
  api.setRefreshHeaderInfo({
      loadingImg: 'widget://image/refresh.png',
      bgColor: '#fdd903',
      textColor: '#fff',
      textDown: '下拉刷新...',
      textUp: '松开刷新...'
  }, function(ret, err) {

    app.vm.pageIndex.init()
      //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
  });

  app.vm.pageIndex = new Vue({
        el: '#pageIndex',
        data: {
          data: {},
          userInfo:{},
          urls:[],
          leastUrls:[]
        },
        created: function() {
           this.userInfo = app.getUserInfo();
          //  console.log(created);

           this.init();
          //  this.onReload();
        },
         methods: {
               init:function(){
                 var that = this;
                 this.getAppIndexUrl();
                 this.getLeastUrls();
                //  统计数据
                 app.get("apiv2/store/find",{

                 },function(res){
                   api.refreshHeaderLoadDone();
                    if(res.code!=200){
                       app.alert(res.msg);
                      return ;
                    }else{
                      that.data=res.data;
                      if(res.data.merchantId){
                         app.cache().set('merchantId',res.data.merchantId);
                      }
                    }
                 });
              },

              getAppIndexUrl:function(){
                var that = this;
                app.get("apiv2/store/appIndexUrl",{},function(res){
                   if(res.code!=200){
                      app.alert(res.msg);
                     return ;
                   }else{
                     that.urls=res.data;
                   }
                });
              },

              getLeastUrls:function(){
                var that = this;
                app.get("apiv2/app_index_url/get",{
                  store_id:this.userInfo.store_id,
                  type:'moreUrl',
                  order:'updatetime desc'
                },function(res){
                   if(res.code!=200){
                      app.alert(res.msg);
                     return ;
                   }else{
                     that.leastUrls=res.data.list;
                   }
                });
              },
              saveLeastUrls:function(id){
                if(!id){
                  return;
                }
                var that = this;
                app.get("apiv2/app_index_url/add",{
                  store_id:this.userInfo.store_id,
                  id:id,
                  order:'updatetime desc'
                },function(res){
                   if(res.code!=200){
                      app.alert(res.msg);
                     return ;
                   }
                });
              },
              openUrl:function(url,title,id){
                  this.saveLeastUrls(id);
                  if(url.indexOf("http")===0){
                     webView(url,title);
                  }else{
                     openFrame(url,url,1);
                  }
              }

         }

  })
}
